package com.git.bds.mr.doctor.controller;

import com.git.bds.mr.doctor.convert.DoctorConvert;
import com.git.bds.mr.doctor.model.dto.RecordModifyDTO;
import com.git.bds.mr.doctor.model.dto.RecordReviseDTO;
import com.git.bds.mr.doctor.service.DoctorService;
import com.git.bds.mr.page.PageParam;
import com.git.bds.mr.page.PageResult;
import com.git.bds.mr.records.model.dto.RecordAddDTO;
import com.git.bds.mr.records.model.dto.RecordDTO;
import com.git.bds.mr.records.service.ch.RecordsService;
import com.git.bds.mr.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 成大事
 * @since 2022/9/26 19:16
 */
@Api(tags = "医生 病历管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/doctorRecords")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class DoctorRecordController {

    private final DoctorService doctorService;

    private final RecordsService recordsService;

    @PostMapping("/getRecordsByPage")
    @ApiOperation("医生获取病历 分页")
    public R<PageResult<RecordDTO>> getRecordsByPage(@Validated @RequestBody PageParam pageParam){
        return R.ok(doctorService.getRecordsByPage(pageParam));
    }

    @PostMapping("/addRecord")
    @ApiOperation("医生添加病历")
    public R<Boolean> addRecord(@Validated @RequestBody RecordAddDTO recordAddDTO){
        return R.decide(doctorService.addRecord(recordAddDTO));
    }

    @PostMapping("/getRecordsReviseByPage")
    @ApiOperation("医生获取病历提交修改的病历 分页")
    public R<PageResult<RecordReviseDTO>> getRecordsReviseByPage(@Validated @RequestBody PageParam pageParam){
        return R.ok(doctorService.getRecordsReviseByPage(pageParam));
    }

    @PostMapping("/reviseRecord")
    @ApiOperation("医生对病人提交的有误病历进行修改")
    public R<Boolean> reviseRecord(
            @Validated @RequestBody RecordModifyDTO recordDTO
    ){
        return R.decide(doctorService.reviseRecord(recordDTO));
    }

    @PostMapping("/correctRecord")
    @ApiOperation("医生对病人提交的有误病历 进行无误处理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "病历id",example = "122134123",readOnly = true,dataTypeClass = Long.class),
            @ApiImplicitParam(name = "reply",value = "回复",example = "没问题啊",readOnly = true,dataTypeClass = String.class)
    })
    public R<Boolean> correctRecord(
            @RequestParam("id") Long id,
            @RequestParam("reply") String reply
    ){
        return R.decide(doctorService.correctRecord(id,reply));
    }

    @PostMapping("/viewMedicalRecord")
    @ApiOperation("医生查看病历")
    @ApiImplicitParam(name = "id",value = "病历id",example = "122134123",readOnly = true,dataTypeClass = Long.class)
    public R<RecordDTO> viewMedicalRecord(
            @RequestParam("id") Long id
    ){
        return R.ok(DoctorConvert.INSTANCE.toRecordDTO(recordsService.getById(id)));
    }


}
